Skip to content

Conversation

@agionoja
Copy link
Contributor

This adds optional colorized output and human-readable formatters for durations and file sizes.

New features:

  • colors option for colorized output (off by default)
  • formatDuration() - formats ms as "1.20s", "45ms", etc.
  • formatFileSize() - formats bytes as "1.2 kB", "120 B", etc.
  • Updated default format to use %durationPretty and %contentLengthPretty

Colors (when enabled):

  • Status codes: green (2xx), cyan (3xx), yellow (4xx), red (5xx)
  • Durations: green (<100ms), yellow (100-500ms), magenta (500ms-1s), red (>1s)
  • Methods: GET (green), POST (cyan), PUT/PATCH (yellow), DELETE (red), HEAD/OPTIONS (magenta)
  • Content length: cyan (1kB-100kB), yellow (100kB-1MB), red (>1MB)

No breaking changes - colors default to off.

@MichaelDeBoey MichaelDeBoey changed the title Feat(logger-middleware) : Add color support and pretty formatters feat(logger-middleware) : add support for color and pretty formatters Nov 25, 2025
@MichaelDeBoey MichaelDeBoey changed the title feat(logger-middleware) : add support for color and pretty formatters feat(logger-middleware): add support for color and pretty formatters Nov 25, 2025
@mjackson
Copy link
Member

Let's default to using color when we detect we are in a TTY. This is going to be tricky since we don't want to lose the ability to run logger middleware in browser/service worker environment.

Something like this could work:

const useColor = typeof process !== 'undefined' &&
  process.stdout.isTTY &&
  process.env.NO_COLOR == null

function colorize(text: string, color: string) {
  return useColor ? `${color}${text}${reset}` : text
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants